package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.NursingLevelDto;
import com.zzyl.nursing.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingLevel;
import com.zzyl.nursing.service.INursingLevelService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理等级Controller
 *
 * @author ljc
 * @date 2025-02-22
 */
@Api(tags = "护理等级")
@RestController
@RequestMapping("/nursing/level")
public class NursingLevelController extends BaseController
{
    @Autowired
    private INursingLevelService nursingLevelService;

    /**
     * 查询护理等级列表
     */
    @ApiOperation(value = "查询护理等级列表")
    @PreAuthorize("@ss.hasPermi('nursingLevel:nursingLevel:list')")
    @GetMapping("/list")
    public TableDataInfo<List<NursingLevelVo>> list(NursingLevel nursingLevel)
    {
        startPage();
        List<NursingLevelVo> list = nursingLevelService.selectNursingLevelVoList(nursingLevel);
        return getDataTable(list);
    }

    /**
     * 导出护理等级列表
     */
    @ApiOperation(value = "导出护理等级列表")
    @PreAuthorize("@ss.hasPermi('nursingLevel:nursingLevel:export')")
    @Log(title = "护理等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @ApiParam(value = "护理等级查询条件")NursingLevel nursingLevel)
    {
        List<NursingLevel> list = nursingLevelService.selectNursingLevelList(nursingLevel);
        ExcelUtil<NursingLevel> util = new ExcelUtil<NursingLevel>(NursingLevel.class);
        util.exportExcel(response, list, "护理等级数据");
    }

    /**
     * 获取护理等级详细信息
     */
    @ApiOperation(value = "获取护理等级详细信息")
    @PreAuthorize("@ss.hasPermi('nursingLevel:nursingLevel:query')")
    @GetMapping(value = "/{id}")
    public R<NursingLevelVo> getInfo(@ApiParam(value = "护理等级ID", required = true) @PathVariable("id") Long id)
    {
        return R.ok(nursingLevelService.selectNursingLevelById(id));
    }

    /**
     * 新增护理等级
     */
    @ApiOperation(value = "新增护理等级")
    @PreAuthorize("@ss.hasPermi('nursingLevel:nursingLevel:add')")
    @Log(title = "护理等级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(value = "护理等级信息", required = true) @RequestBody NursingLevelDto nursingLevelDto)
    {
        return toAjax(nursingLevelService.insertNursingLevel(nursingLevelDto));
    }

    /**
     * 修改护理等级
     */
    @ApiOperation(value = "修改护理等级")
    @PreAuthorize("@ss.hasPermi('nursingLevel:nursingLevel:edit')")
    @Log(title = "护理等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "护理等级信息", required = true) @RequestBody NursingLevelDto nursingLevelDto)
    {
        return toAjax(nursingLevelService.updateNursingLevel(nursingLevelDto));
    }

    /**
     * 删除护理等级
     */
    @ApiOperation(value = "删除护理等级")
    @PreAuthorize("@ss.hasPermi('nursingLevel:nursingLevel:remove')")
    @Log(title = "护理等级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam(value = "护理等级ID数组", required = true)@PathVariable Long[] ids)
    {
        return toAjax(nursingLevelService.deleteNursingLevelByIds(ids));
    }
    /**
     * 查询所有护理等级
     */
    @ApiOperation(value = "获取护理等级详细信息")
    @PreAuthorize("@ss.hasPermi('nursingLevel:nursingLevel:query')")
    @GetMapping(value = "/listAll")
    public R<List<NursingLevelVo>>listAll()
    {
        List<NursingLevelVo> list=nursingLevelService.listAll();
        return R.ok(list);
    }
}
